# -*- coding: utf-8 -*-
from openerp.osv import fields
from openerp.osv import osv
from openerp import SUPERUSER_ID


class product_package(osv.osv):
    _name = 'product.package'
    _columns = {
        'user_id': fields.many2one('res.users', u'包货负责人'),
        'so_id': fields.many2one('sale.order', u'销售订单'),
        'name': fields.char(u'包货单号'),
        'package_qty': fields.float(u'包货份数'),
        'start_datetime': fields.date(u'起始时间'),
        'end_datetime': fields.date(u'起始时间'),
        'person_qty': fields.integer(u'参与人数'),
        'is_print': fields.boolean(u'已打印'),
        'is_done': fields.boolean(u'包货完成'),
        'product_name': fields.char(u'套装名称'),
        'note': fields.text(u'备注'),
        'product_package_line': fields.one2many('product.package.line', 'package_id', u'卡券提货选项'),
    }

    _defaults = {
        'name': lambda self, cr, uid, c: self.pool.get('ir.sequence').get(cr, uid, 'product_package_order') or '',
    }

    def return_action(self, cr, uid, res_ids, module_name, action_xml_id, form_or_tree_xml, return_type='tree', domain=[], context=None):
        mod_obj = self.pool.get('ir.model.data')
        act_obj = self.pool.get('ir.actions.act_window')
        result = mod_obj.get_object_reference(
            cr, uid, module_name, action_xml_id)
        id = result and result[1] or False
        result = act_obj.read(cr, uid, [id], context=context)[0]
        res = mod_obj.get_object_reference(
            cr, uid, module_name, form_or_tree_xml)
        result['domain'] = domain
        result['views'] = [(res and res[1] or False, return_type)]
        result['res_id'] = res_ids or False
        return result

class product_package_line(osv.osv):

    _name = 'product.package.line'
    _columns = {
        'product_id': fields.many2one('product.product', u'产品'),
        'product_name': fields.char(u'产品名称'),
        'product_qty': fields.float(u'产品数量'),
        'package_id': fields.many2one('product.package', u'打包ID'),
    }

    _defaults = {

    }




